package com.example.github.jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;

/**
 * 创建druid 数据库连接池
 */
public class DruidJDBC {
    public static void main(String[] args) throws Exception {
        // 1. 导入jar 包 2. 定义配置文件 3.加载配置文件
        Properties properties = new Properties();
        properties.load(new FileInputStream("postman/src/main/resources/druid.properties"));
        // 4. 获取连接池对象
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        // 5. 创建连接
        Connection connection = dataSource.getConnection();
        // 6. 执行查询语句
        String sql = "update person set name = 'admin' where id = 1";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        int update = preparedStatement.executeUpdate();
        System.out.println(update);
    }
}
